<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function getMessage($code=0,$msg='',$data=[]){

        return json_encode(['code'=>$code,'message'=>$msg,'data'=>$data]);
    }

    public function getSessionInfo(Request $request,$code='success',$message=''){
        if($code == 'success'){
            if($message) {
                $request->session()->flash('success', $message);
            }else{
                $request->session()->flash('success', '创建成功');
            }
        }elseif($code == 'notice'){
            if($message) {
                $request->session()->flash('notice', $message);
            }else{
                $request->session()->flash('notice', '数据不合理');
            }
        }else{
            if($message){
                $request->session()->flash('error',$message);
            }else{
                $request->session()->flash('error','创建失败');
            }

        }
    }
}
